Skip to content

[nest] Use AST-based CommonJS import rewriting#2001

Open
boomyao wants to merge 1 commit into
vercel:mainfrom
boomyao:yao/nest-cjs-ast-rewrite
Open

[nest] Use AST-based CommonJS import rewriting#2001
boomyao wants to merge 1 commit into
vercel:mainfrom
boomyao:yao/nest-cjs-ast-rewrite

Conversation

@boomyao
Copy link
Copy Markdown
Contributor

@boomyao boomyao commented May 15, 2026

Summary

  • replace the Nest CommonJS import rewrite regex with SWC AST parsing
  • rewrite named, multiline, default, namespace, and side-effect relative .ts/.tsx imports
  • map SWC UTF-8 byte spans back to string indexes, including leading non-ASCII comments

Testing

  • pnpm biome check packages/nest/src/cjs-rewrite.ts packages/nest/src/cjs-rewrite.test.ts .changeset/nest-cjs-ast-rewrite.md
  • pnpm --filter @workflow/nest test
  • pnpm turbo build --filter=@workflow/nest...

Signed-off-by: yao <zhangyaoruo@outlook.com>
@boomyao boomyao requested a review from a team as a code owner May 15, 2026 08:17
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

🦋 Changeset detected

Latest commit: ac21487

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@workflow/nest Patch
workflow Patch
tarballs Patch
@workflow/ai Patch
@workflow/world-testing Patch
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/web Patch
@workflow/astro Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 15, 2026

@boomyao is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

}

function getLeadingSyntaxByteOffset(source: string): number {
let index = source.startsWith('#!') ? skipLineComment(source, 0) : 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let index = source.startsWith('#!') ? skipLineComment(source, 0) : 0;
let index = 0;

SWC byte position mapper computes incorrect offset for files with shebang lines, causing Unable to map SWC byte position X to a string index errors.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant